package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.domain.BizSeller;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BizStore;
import com.ruoyi.business.service.IBizStoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 店铺招商Controller
 * 
 * @author ruoyi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/business/store")
public class BizStoreController extends BaseController
{
    @Autowired
    private IBizStoreService bizStoreService;

    /**
     * 查询店铺招商列表
     */
    @PreAuthorize("@ss.hasPermi('business:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizStore bizStore)
    {
        startPage();
        List<BizStore> list = bizStoreService.selectBizStoreList(bizStore);
        return getDataTable(list);
    }

    /**
     * 导出店铺招商列表
     */
    @PreAuthorize("@ss.hasPermi('business:store:export')")
    @Log(title = "店铺招商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizStore bizStore)
    {
        List<BizStore> list = bizStoreService.selectBizStoreList(bizStore);
        ExcelUtil<BizStore> util = new ExcelUtil<BizStore>(BizStore.class);
        util.exportExcel(response, list, "店铺招商数据");
    }

    /**
     * 获取店铺招商详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:store:query')")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
    {
        return success(bizStoreService.selectBizStoreByStoreId(storeId));
    }

    /**
     * 新增店铺招商
     */
    @PreAuthorize("@ss.hasPermi('business:store:add')")
    @Log(title = "店铺招商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizStore bizStore)
    {
        bizStore.setTenantId(getUserId());
        return toAjax(bizStoreService.insertBizStore(bizStore));
    }

    /**
     * 修改店铺招商
     */
    @PreAuthorize("@ss.hasPermi('business:store:edit')")
    @Log(title = "店铺招商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizStore bizStore)
    {
        return toAjax(bizStoreService.updateBizStore(bizStore));
    }
    @PreAuthorize("@ss.hasPermi('business:store:edit')")
    @Log(title = "商户申请", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody BizStore bizStore)
    {
        return toAjax(bizStoreService.updateBizStore(bizStore));
    }
    /**
     * 删除店铺招商
     */
    @PreAuthorize("@ss.hasPermi('business:store:remove')")
    @Log(title = "店铺招商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds)
    {
        return toAjax(bizStoreService.deleteBizStoreByStoreIds(storeIds));
    }
}
